package com.example.server.config;

import com.alibaba.druid.pool.DruidDataSource;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class DruidConfig {

    @Bean
    // 将 application.properties 中以 spring.dataSource 开头的配置项的值赋值给 DruidDataSource 中对应的属性
    // 例如 spring.datasource.username=root 就等价于给 dataSource 这个对象的 username 属性赋值
    @ConfigurationProperties(prefix="spring.datasource")
    public DruidDataSource dataSource() {
        DruidDataSource druid = new DruidDataSource();
        return druid;
    }
}
